package com.seal.tsms.exam.controller;

import com.seal.tsms.base.controller.BaseController;
import com.seal.tsms.base.service.BaseService;
import com.seal.tsms.exam.entity.Grade;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap;

import java.util.List;

/**
 * Created by asus on 2016/6/6.
 */
@Controller
@RequestMapping("/grade")
public class GradeController extends BaseController<Grade,String> {
    @Override
    @Autowired
    @Qualifier("gradeServiceImpl")

    public void setSelfService(BaseService<Grade, String> selfService) {
        super.setSelfService(selfService);
    }


    @RequestMapping(value = "/save",method = RequestMethod.GET)
    public String create(){
        return "exam/grade/add";

    }
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public  String save(Grade grade, RedirectAttributesModelMap redirectAttributesModelMap){
        getSelfService().save(grade);

        redirectAttributesModelMap.addFlashAttribute("msg","c成功保存一条数据");
        return "redirect:list.action";

    }
    @RequestMapping(value = "/list")
    public String list(ModelMap modelMap){
         List<Grade> grades=(List<Grade>)getSelfService().list(DetachedCriteria.forClass(Grade.class),null);
         modelMap.addAttribute("grades",grades);
        return "exam/grade/list";

    }

}
